package com.netease.pris.persist;

import com.db4o.ObjectSet;
import com.netease.pris.meta.WorkSet;

/**
 * 
 * @author Administrator
 * 
 */
public class WorkSetPersist extends BasePersist {

	private static WorkSetPersist persist = new WorkSetPersist();

	private WorkSetPersist() {
	}

	public static WorkSetPersist getPersist() {
		return persist;
	}

	public void add(WorkSet workset) {
		if(queryById(workset.getWorkSetId()) == null){
			getContainer().store(workset);
		}
		return;
	}

	public void update(WorkSet workset) {
		getContainer().store(workset);
	}

	public WorkSet queryById(String id) {
		WorkSet h = new WorkSet();
		h.setWorkSetId(id);
		ObjectSet<WorkSet> hosts = getContainer().queryByExample(h);
		if (hosts != null && hosts.size() > 0) {
			return hosts.get(0);
		}
		return null;
	}

	public void deleteHost(WorkSet workset) {
		getContainer().delete(workset);
	}

	public ObjectSet<WorkSet> getAll() {
		return getContainer().query(WorkSet.class);
	}

	public ObjectSet<WorkSet> query(WorkSet workset) {
		return getContainer().queryByExample(workset);
	}

}
